package com.ruoyi.web.controller.admin.project;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.ProjectTrack;
import com.ruoyi.system.service.IProjectTrackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("admin/project/track")
@Api(tags = "项目客户追踪")
public class ProjectTrackController extends BaseController {

    @Autowired
    private IProjectTrackService projectTrackService;

    @PostMapping("/add")
    @ApiOperation("新增追踪记录")
    public AjaxResult add(@RequestBody ProjectTrack track) {
        return projectTrackService.add(track) > 0 ? AjaxResult.success() : AjaxResult.error("新增失败");
    }

    @PutMapping("/update")
    @ApiOperation("更新追踪记录")
    public AjaxResult update(@RequestBody ProjectTrack track) {
        return projectTrackService.update(track) > 0 ? AjaxResult.success() : AjaxResult.error("更新失败");
    }

    @DeleteMapping("/del/{id}")
    @ApiOperation("删除追踪记录")
    public AjaxResult delete(@PathVariable Long id) {
        return projectTrackService.deleteById(id) > 0 ? AjaxResult.success() : AjaxResult.error("删除失败");
    }

    @GetMapping("/get/{id}")
    @ApiOperation("获取追踪记录详情")
    public AjaxResult get(@PathVariable Long id) {
        return AjaxResult.success(projectTrackService.getById(id));
    }

    @GetMapping("/list/{projectId}")
    @ApiOperation("按项目ID查询追踪记录列表")
    public AjaxResult listByProject(@PathVariable Long projectId) {
        List<ProjectTrack> list = projectTrackService.listByProjectId(projectId);
        return AjaxResult.success(list);
    }
}


